package servlet;

import model.User;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.io.IOException;

/**
 * @Title: logout
 * @Author 郑雨杭
 * @Package servlet
 * @Date 2024/7/30 14:31
 * @description:
 */
@WebServlet("/logout")
public class logout extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        HttpSession session = req.getSession(false);
        if(session!=null){
            User user = (User) session.getAttribute("user");
            if(user!=null){
                session.removeAttribute("user");
            }
        }
        resp.sendRedirect(req.getContextPath()+"/login.html");
    }
}
